******************************************************************
******************************************************************
*Schito, Marco: The politics of State aid in the European Union: explaining variation in aid allocation among Member States
*Published in: Journal of Public Policy
*Stata do file for replication analysis of interaction plots: Figures 4 to 6 
******************************************************************
******************************************************************



sysuse auto, clear
use jpp_state_aid.dta
xtset country1 year

gen yline = 0

***Interaction plots***

***FIGURE 4

***Economic Policy x ENOP 

xtpcse logsa L_incentives1 L_enop1 c.L_incentives1#c.L_enop1 ///
	L_vprange c.L_incentives1#c.L_vprange  ///
	L_realecongrowth L_koftr L_koffi fmelecindex emu L_debt L_unemp ///
	logmdmh persindex c.logmdmh#c.persindex ///
	reg1999z c.L_incentives1#c.reg1999z i.country1, cor(ar1)  pairwise
	
matrix b=e(b) 
matrix V=e(V)
 
scalar b1=b[1,1]
scalar b11=b[1,2]
scalar b12=b[1,3]

scalar varb1=V[1,1]
scalar varb11=V[2,2]  
scalar varb12=V[3,3]

scalar covb1b12=V[1,3] 
scalar covb11b12=V[2,3]

scalar list b1 b11 b12 varb1 varb12 varb11 covb1b12 covb11b12

***Economic Policy x ENOP assuming EP as X and ENOP as Z

generate MVZx=((_n-1)/10)
replace  MVZx=. if _n>71
gen conbxx=b1+b12*MVZx if _n<72
gen conbxxse=sqrt(varb1+varb12*(MVZx^2)+2*covb1b12*MVZx) if _n<72
gen axx=1.96*conbxxse 
gen upperxx=conbxx+axx 
gen lowerxx=conbxx-axx

**Figure 4 only includes this paragraph of code
graph twoway hist L_enop1, width(1) percent color(gs14) yaxis(2) ///
		||	 line conbxx   MVZx, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upperxx  MVZx, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lowerxx MVZx, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MVZx,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xlabel(0 1 2 3 4 5 6 7, nogrid labsize(2.5)) /// 
			 xscale(noline) ///
             ylabel(-0.25 0 0.25, axis(1) nogrid  labsize(2.5)) ///
			 ylabel(0 5 10 15 20 25 30 35, axis(2) nogrid labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt axis(2)) ///
			 legend(off) ///
             xtitle("{it:Coalition}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:Economic Policy}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(incentivesxenop, replace)
			 
***Economic Policy x ENOP assuming EP as Z and ENOP as X

generate MVZx1=((_n-1)/10)
replace  MVZx1=. if _n>148.4
gen conbxx1=b11+b12*MVZx1 if _n<148.5
gen conbxxse1=sqrt(varb11+varb12*(MVZx1^2)+2*covb11b12*MVZx1) if _n<148.5
gen axx1=1.96*conbxxse1 
gen upperxx1=conbxx1+axx1 
gen lowerxx1=conbxx1-axx1


graph twoway hist L_incentives1, width(0.3) percent color(gs14) yaxis(2) ///
		||	 line conbxx1   MVZx1, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upperxx1  MVZx1, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lowerxx1 MVZx1, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MVZx1,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xlabel(0 3 6 9 12 15, nogrid labsize(2.5)) /// 
			 xscale(noline) ///
             ylabel(-0.5 -0.25 0 0.25, axis(1) nogrid  labsize(2.5)) ///
			 ylabel(0 2 4 6 8 10, axis(2) nogrid labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt axis(2)) ///
			 legend(off) ///
             xtitle("{it:Economic Policy}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:Coalition}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(enopxincentives, replace)

 
 ***FIGURE 5
 
***Reg1999 x Economic Policy

xtpcse logsa L_incentives1 reg1999z c.L_incentives1#c.reg1999z ///
	L_enop1 L_vprange ///
	c.L_incentives1#c.L_enop1 c.L_incentives1#c.L_vprange  ///
	L_realecongrowth L_koftr L_koffi fmelecindex emu L_debt L_unemp ///
	logmdmh persindex c.logmdmh#c.persindex i.country1, cor(ar1) pairwise

matrix b=e(b)
matrix V=e(V)
 
scalar b1=b[1,1]
scalar b2=b[1,2]
scalar b3=b[1,3]


scalar varb1=V[1,1]
scalar varb2=V[2,2]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]
scalar covb2b3=V[2,3]

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3

***Reg1999 x Economic Policy assuming reg as Z and EP as X

generate MV=((_n-1)/10)
replace  MV=. if _n>121

gen conb=b1+b3*MV if _n<121.1
gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) if _n<121.1

gen aa=1.96*conse 
gen upper=conb+aa 
gen lower=conb-aa

**Figure 5 only includes this paragraph of code
graph twoway hist reg1999z, width(1) percent color(gs14) yaxis(2) ///
		||	 line conb   MV, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upper  MV, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lower  MV, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MV,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xlabel(0 3 6 9 12,  nogrid labsize(2.5)) /// 
			 xscale(noline) ///
             ylabel(-0.1 -0.05 0 0.05 0.1 0.15 0.2, axis(1) nogrid  labsize(2.5)) ///
			 ylabel(0 10 20 30, axis(2) nogrid  labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt axis(2)) ///
             xscale(noline) ///
             legend(off) ///
             xtitle("{it:Regulation}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:Economic Policy}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(incentivesxreg, replace)
			 
			 
***Reg1999 x Economic Policy assuming reg as X and EP as Z

generate MV2=((_n-1)/10)
replace  MV2=. if _n>148.4


gen conb2=b2+b3*MV2 if _n<148.5
gen conse2=sqrt(varb2+varb3*(MV2^2)+2*covb2b3*MV2) if _n<148.5

gen aa2=1.96*conse2 
gen upper2=conb2+aa2 
gen lower2=conb2-aa2


graph twoway hist L_incentives1, width(0.3) percent color(gs14) yaxis(2) ///
		||	 line conb2   MV2, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upper2  MV2, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lower2  MV2, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MV2,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xlabel(0 3 6 9 12 15, nogrid labsize(2.5)) /// 
			 xscale(noline) ///
             ylabel(-0.15 -0.1 -0.05 0 0.05 0.1 0.15, axis(1) nogrid  labsize(2.5)) ///
			 ylabel(0 2 4 6 8 10, axis(2) nogrid labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt axis(2)) ///
             xscale(noline) ///
             legend(off) ///
             xtitle("{it:Economic Policy}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:Regulation}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(regxincentives, replace)

			 
***FIGURE 6

xtpcse logsa logmdmh persindex c.logmdmh#c.persindex ///
	L_incentives1 L_enop1 L_vprange ///
	c.L_incentives1#c.L_enop1 c.L_incentives1#c.L_vprange ///
	L_realecongrowth L_koftr L_koffi fmelecindex emu L_debt L_unemp ///
	reg1999z c.L_incentives1#c.reg1999z i.country1, cor(ar1) pairwise

***this is for DMxPV and PVxDM and all these values should be in common
matrix b=e(b) 
matrix V=e(V)
 
scalar b1=b[1,1]
scalar b16=b[1,2]
scalar b17=b[1,3]

scalar varb1=V[1,1]
scalar varb16=V[2,2]  
scalar varb17=V[3,3]

scalar covb1b17=V[1,3] 
scalar covb16b17=V[2,3]

scalar list b1 b16 b17 varb1 varb17 varb16 covb1b17 covb16b17

***District Magnitude x Personal Vote assuming PV as X and DM as Z

generate MVZ=((_n-1)/10)
replace  MVZ=. if _n>51.1

gen conbx=b1+b17*MVZ if _n<51.2
gen conbxse=sqrt(varb1+varb17*(MVZ^2)+2*covb1b17*MVZ) if _n<51.2
gen ax=1.96*conbxse 
gen upperx=conbx+ax 
gen lowerx=conbx-ax


graph twoway hist logmdmh, width(0.1) percent color(gs14) yaxis(2) ///
		||	 line conbx   MVZ, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upperx  MVZ, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lowerx  MVZ, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MVZ,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xlabel(0 1 2 3 4 5, nogrid labsize(2.5)) /// 
			 xscale(noline) ///
             ylabel(-1 0 1 2 3, axis(1) nogrid labsize(2.5)) ///
			 ylabel(0 5 10 15 20 25, axis(2) nogrid labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt axis(2)) ///
			 legend(off) ///
             xtitle("{it:District Magnitude}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:Personal Vote}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(dmxpi, replace)
 

***Personal Vote x District Magnitude assuming PV as Z and DM as X

generate MVX=((_n-1)/100)
replace  MVX=. if _n>177

gen conbz=b16+b17*MVX if _n<178
gen conbzse=sqrt(varb16+varb17*(MVX^2)+2*covb16b17*MVX) if _n<178
gen az=1.96*conbzse 
gen upperz=conbz+az 
gen lowerz=conbz-az

graph twoway hist persindex, width(0.1) percent color(gs14) yaxis(2) ///
		||	 line conbz   MVX, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upperz  MVX, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lowerz  MVX, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MVX,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xlabel(0 0.5 1 1.5, nogrid labsize(2.5)) /// 
			 xscale(noline) ///
             ylabel(-1.5 -1 -0.5 0 0.5 1, axis(1) nogrid  labsize(2.5)) ///
			 ylabel(0 10 20 30 40, axis(2) nogrid labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt axis(2)) ///
			 legend(off) ///
             xtitle("{it:Personal Vote}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:District Magnitude}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(pixdm, replace)

***The following figures include both interaction plots. They can be found in Appendix B

**FIGURE B1
graph combine incentivesxenop.gph enopxincentives.gph, col(2)  graphregion(fcolor(white)) saving(figure_b1, replace)

**FIGURE B2
graph combine incentivesxreg.gph regxincentives.gph, col(2)  graphregion(fcolor(white)) saving(figure_b2, replace)

**FIGURE B3
graph combine dmxpi.gph pixdm.gph, col(2) graphregion(fcolor(white)) saving(figure_b3, replace)


